package com.company.project.rest;

import com.company.project.constant.TradeEnums;
import com.company.project.protocol.user.ChangeUserMoneyReq;
import com.company.project.protocol.user.ChangeUserMoneyRes;
import com.company.project.protocol.user.QueryUserReq;
import com.company.project.protocol.user.QueryUserRes;
import com.company.project.web.TradeUserController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

@Api(value="用户服务")
@Component
@RestController
@RequestMapping("/trade/user")
public class UserApi  extends TradeUserController {
    @Resource
    public GoodsApi goodsApi;

    /**
     * 查询用户
     * @param queryUserReq
     * @return
     */
    @Override
    @ResponseBody
    @ApiOperation(value="查询用户服务")
    @PostMapping("/queryUser")
    public QueryUserRes queryUser(@Valid QueryUserReq queryUserReq) {
        return  this.tradeUserService.queryUser(queryUserReq);
    }

    /**
     * 修改用户余额
     * @param changeUserMoneyReq
     * @return
     */
    @Override
    @ResponseBody
    @ApiOperation(value="修改用户余额")
    @PostMapping("/changeUserMoney")
    public ChangeUserMoneyRes changeUserMoney( ChangeUserMoneyReq changeUserMoneyReq) {
        // 修改操作 用 try catch 包装 里面抛出的异常( 在里面没有捕获的话，就在外面捕获)
        ChangeUserMoneyRes changeUserMoneyRes = new ChangeUserMoneyRes();
        try {
            changeUserMoneyRes = this.tradeUserService.changeUserMoney(changeUserMoneyReq);
        } catch (Exception ex) {
            changeUserMoneyRes.setRetCode(TradeEnums.RetEnum.FAIL.getCode());
            changeUserMoneyRes.setRetInfo(ex.getMessage());
        }
        return changeUserMoneyRes;

    }

}


